BlueCielo Meridian Enterprise 2012 Developer's Guide | BlueCielo ECM Solutions

Accessing a vault from Visual Basic for Applications

The sample code below demonstrates how to access an AMDocument object from Visual Basic for Applications, in this case, Microsoft Word. The AMNameSpace object uses the file system path to identify the document. It then connects to the vault and launches the AMDocument object. This functionality can be used to read or write Meridian Enterprise property values from script macros.

Example
Private Sub Document_Open()
If (Not Application.ActiveDocument.ReadOnly) Then On Error GoTo errh
Dim doc As AMDocument
Dim props As AMPropertyCollection
' Create the AMNameSpace object
Dim ns As New AMNameSpace
' AMNameSpace requires the full path to return the AMDocument object
Set doc = ns.DocumentFromPath(ThisDocument.FullName)
' Now we can read property values from the vault
Set props = doc.LoadProperties("PSAddress")
ThisDocument.FormFields("text1").Result = props.Get("Contact_BSTR").Value
ThisDocument.FormFields("text2").Result = props.Get("Companyname_BSTR").Value
ThisDocument.FormFields("text3").Result = props.Get("Faxnumber_BSTR").Value
' Clean up to release all references to the vault
Set props = Nothing
Set doc = Nothing
Else
MsgBox "This document is read-only, or not a working copy. You'll not be able to write any changes"
End If
errh:
If (Err.Number = 5) Then
MsgBox "This document is not managed by Meridian Enterprise.", _ vbOKOnly, "Meridian Enterprise"
End If
End Sub

Copyright © 2000-2012 BlueCielo ECM Solutions